package com.tsinjie.metadata.database.comment.factory;

import com.tsinjie.metadata.database.comment.TableComment;
import com.tsinjie.metadata.database.comment.support.MySQLTableComment;

import java.sql.Connection;
import java.sql.SQLException;

/**
 * Created by LiuXunming on 2015-10-13.
 * 表注释生成 工厂类
 */
public class TableCommentFactory {
    /**
     * mysql
     */
    public static final String DATABASE_MYSQL = "mysql";

    /**
     * 获取表的注释
     *
     * @param conn
     * @param tableName
     * @param schemaName
     * @return
     * @throws java.sql.SQLException
     */
    public static String getComment(Connection conn, String tableName, String schemaName) throws SQLException {
        /*数据库类型*/
        String databaseProductName = conn.getMetaData().getDatabaseProductName();
        TableComment tableComment = null;
        if (databaseProductName.equalsIgnoreCase(DATABASE_MYSQL)) {/*mysql数据库*/
            tableComment = new MySQLTableComment();
        }
        return tableComment == null ? null : tableComment.getComment(conn, tableName, schemaName);
    }
}
